package com.example.basic.lifecycle;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;

import com.example.basic.base.BaseActivity;
import com.example.basic.logs.Logger;
import com.example.basic.utils.ApplicationContextUtils;

public class ActivityLifecycleLogger implements LifecycleObserver {

    private static BaseActivity mBaseActivity;

    public ActivityLifecycleLogger(BaseActivity activity) {
        this.mBaseActivity = activity;
    }

    private boolean printLogEnable() {
        boolean logEnable = ApplicationContextUtils.getAppSharedPreferences().getBoolean(Logger.ACTIVITY_LIFE_CYCLE_PRINT_ENABLE,false);
        return logEnable;
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    public void onActivityCreate(){
        if (printLogEnable()) {
            Logger.i(mBaseActivity.getTag(),"Lifecycle.Event.ON_CREATE");
        }
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    public void onActivityStart(){
        if (printLogEnable()) {
            Logger.i(mBaseActivity.getTag(),"Lifecycle.Event.ON_START");
        }
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    public void onActivityResume(){
        if (printLogEnable()) {
            Logger.i(mBaseActivity.getTag(),"Lifecycle.Event.ON_RESUME");
        }
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    public void onActivityPause(){
        if (printLogEnable()) {
            Logger.i(mBaseActivity.getTag(),"Lifecycle.Event.ON_PAUSE");
        }
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    public void onActivityStop(){
        if (printLogEnable()) {
            Logger.i(mBaseActivity.getTag(),"Lifecycle.Event.ON_STOP");
        }
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    public void onActivityDestory(){
        if (printLogEnable()) {
            Logger.i(mBaseActivity.getTag(),"Lifecycle.Event.ON_DESTROY");
        }
    }

}
